<template>
  <el-container class="homeContainer">
    <el-header>
      <div>
        <img src="../assets/logo.png" />
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isToggle===true? '64px' : '200px'">
        <div class="toggle-button" @click="toggle">lll</div>
        <!--default-active="/users" 点击哪个让那个高亮显示 值是对应链接的index-->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409eff"
          unique-opened
          :collapse="isToggle"
          :collapse-transition="false"
          router
          :default-active="status"
        >
          <!-- 通过双层循环设置一级二级路由 -->
          <el-submenu :index="iteam.id+''" v-for="iteam in menulist" :key="iteam.id">
            <template slot="title">
              <i :class="icons[iteam.id]"></i>
              <span class="pace">{{iteam.authName}}</span>
            </template>
            <!-- 通过设置router属性，index的值将会成为子路由的跳转链接 -->
            <el-menu-item
              :index="'/'+item.path"
              v-for="item in iteam.children"
              :key="item.id"
              @click="fontLight('/'+item.path)"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{item.authName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      menulist: [],
      icons: {
        125: "iconfont iconusers",
        103: "iconfont icontijikongjian",
        101: "iconfont iconshangpin",
        102: "iconfont icondanju",
        145: "iconfont iconbaobiao"
      },
      isToggle: false,
      status: ""
    };
  },
  created() {
    this.getmenuList();
    this.status = window.sessionStorage.getItem("path");
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getmenuList() {
      const { data: res } = await this.$http.get("/menus");
      console.log(res);

      if (res.meta.status != 200) {
        return this.$message.error(res.meta.msg);
      } else {
        this.menulist = res.data;
      }
    },
    toggle() {
      this.isToggle = !this.isToggle;
    },
    fontLight(path) {
      window.sessionStorage.setItem("path", path);
      this.status = path;
    }
  }
};
</script>
<style lang="less" scoped>
.el-header {
  background-color: #373d41;
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 20px;
  padding-left: 0px;
  div {
    display: flex;
    align-items: center;
    img {
      width: 40px;
      height: 40px;
    }
    span {
      margin-left: 15px;
    }
  }
}
.homeContainer {
  height: 100%;
}
.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: 0px;
    .pace {
      margin-left: 10px;
    }
  }
  .toggle-button {
    background-color: #4a5064;
    font-size: 10px;
    line-height: 24px;
    color: white;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
}

.el-main {
  background-color: #eaedf1;
  color: #333;
}

body > .el-container {
  margin-bottom: 40px;
}
</style>
</style>